import dt from '@dt/dt'
import clueCustomerMgr from '@/biz/customer/clueCustomer.js'
import dateOpt from '@/biz/option/date.js'
import CustomerMgr from '@/biz/customer/customerOpt.js';
let _this = null
let customerStatusList = [
  { key: 1, value: '线索客户' },
  { key: 2, value: '到访客户' },
  { key: 3, value: '成交客户' },
]

function options(vm, head) {
  _this = vm
  return [
    {
      type: 'checkbox',
      width: 40,
      fixed: 'left',
      showOverflow: false,
      cell: {
        // hereto  	是否到访(1.未到访,2.自己到访，3他人到访)
        value: (row) => {
          return row.newUserId != row.userId ?
            '该客户的“现归属顾问”已变更，与分配记录不同，不可重新分配' : row.hereto != 1 ? "该客户已到访本案场（已到访），不可重新分配" :
            ''
        },
        text: {
          placement: 'right',
          width: '40px',
          position: 'relative',
          height: '20px',
          left: '-10px',
          opacity: 0
        }
      },
    },
    {
      field: 'oldUserName',
      minWidth: 120,
      header: {
        filter: {
          title: '原归属顾问',
          key: 'oldUserId',
          placeholder: '请选择原归属顾问',
          load: (o) => {
            o.select.options = clueCustomerMgr.consultants1()
          },
          select: {
            options: [],
            // multiple: true,
            filterable: true,
            remote: (key) => {
              return clueCustomerMgr.selectTeamUser(key)
            }
          }
        },

      },
    },
    {
      field: 'newUserName',
      minWidth: 120,
      header: {
        filter: {
          title: '现归属顾问',
          key: 'newUserId',
          placeholder: '请选择现归属顾问',
          load: (o) => {
            o.select.options = clueCustomerMgr.consultants1()
          },
          select: {
            options: [],
            // multiple: true,
            filterable: true,
            remote: (key) => {
              return clueCustomerMgr.selectTeamUser(key)
            }
          }
        },

      },
      // slots: {
      //   default: (params, h) => {
      //     return [h('div',
      //       `${params.row.clCounselorName}(${params.row.clCounselorWorkNo})`)]
      //   }
      // }
    },


    {
      field: 'customerName',
      minWidth: 120,
      header: {
        filter: {
          title: '客户姓名',
          key: 'customerName',
          placeholder: '请输入客户姓名',
          input: {}
        }
      }
    },
    {
      field: 'customerPhone',
      minWidth: 130,
      header: {
        filter: {
          title: '手机号码',
          key: 'customerPhone',
          placeholder: '请输入手机号码',
          input: {}
        }
      }
    },


    {
      field: 'channelName',
      minWidth: 160,
      header: {
        filter: {
          title: '线索来源渠道',
          key: 'channelSource',
          placeholder: '请选择线索来源渠道',
          load: (o) => {
            o.select.options = clueCustomerMgr.channelSource()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    },
    {
      field: 'customerStatus',
      minWidth: 120,
      header: {
        filter: {
          title: '客户进度',
          key: 'customerStatusList',
          placeholder: '请选择客户进度',
          load: (o) => {
            o.select.options = customerStatusList
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    },
    {
      field: 'intentionLevel',
      minWidth: 120,
      header: {
        filter: {
          title: '意向等级',
          key: 'intentionLevel',
          placeholder: '请选择意向等级',
          load: (o) => {
            o.select.options = CustomerMgr.intentionLevel()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    },
    {
      field: 'reason',
      minWidth: 120,
      header: {
        filter: {
          title: '进池原因',
          key: 'reasons',
          placeholder: '请选择进池原因',
          // load: (o) => {
          //   o.select.options = CustomerMgr.intentionLevel()
          // },
          select: {
            options: [{
              key: 1,
              value: '无效客户'
            }, {
              key: 2,
              value: '顾问离案'
            }],
            multiple: true,
            filterable: true,
          }
        }
      }
    },

    {
      title: '入池时间',
      field: 'publicPoolTime',
      minWidth: 180,

      header: {
        filter: dateOpt.range({
          title: '入池时间',
          placeholder: '请选择入池时间',
          startKey: 'poolStartTime',
          endKey: 'poolEndTime',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.poolStartTime, val
                .poolEndTime).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('认购日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.poolStartTime, val
              .poolEndTime).Y >= 2)
          }
        }),
      },
    },

    {
      title: '分配日期',
      field: 'distributionTime',
      minWidth: 180,

      header: {
        filter: dateOpt.range({
          title: '分配日期',
          placeholder: '请选择分配日期',
          startKey: 'distributionStartTime',
          endKey: 'distributionEndTime',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.distributionStartTime, val
                .distributionEndTime).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('认购日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.distributionStartTime, val
              .distributionEndTime).Y >= 2)
          }
        }),
      },
    },
    {
      title: '分配人',
      field: 'distributionUserName',
      minWidth: 120,
    },


    {
      field: 'handles',
      title: '操作',
      width: 150,
      fixed: 'right',
      align: 'center',
      className: 'conciseContent',
      slots: {
        default: (params, h) => {
          return [h(
            'div', {
              style: {
                display: 'flex',
                flexDirection: 'column',
              },
            },
            [
              h(
                'Button', {
                  props: {
                    type: 'text',
                  },
                  style: {
                    cursor: 'pointer',
                    padding: '0 5px',
                    color: '#0F42A7'
                  },
                  on: {
                    click: (e) => {
                      e.stopPropagation()
                      _this.getDetail(params.row)
                    },
                  },
                },
                '查看详情'
              ),

            ]
          )]
        }
      }
    }
  ]
}

export default {
  options
}